package com.lsh.airticket.controller;

import com.lsh.airticket.dto.Result;
import com.lsh.airticket.dto.ShowTicket;
import com.lsh.airticket.dto.TicketInformation;
import com.lsh.airticket.entity.Ticket;
import com.lsh.airticket.service.TicketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lsh
 * @date 2021/2/16
 **/
@RestController
// @CrossOrigin
@RequestMapping("/flights")
public class TicketController {

    @Autowired
    TicketService ticketService;


    @GetMapping("/ticket/findTicketList")
    public Result findTicketList(String flightId) {
        List<ShowTicket> tickets = ticketService.FindTicketByFlightId(flightId);
        return Result.result().addData("tickets", tickets);
    }

    @GetMapping("/ticket/findTicketInformation")
    public Result findTicketInformation(String flightId, Integer ticketId) {
        TicketInformation ticketInformation = ticketService.findTicketInformation(ticketId, flightId);
        return Result.result().addData("ticketInformation",ticketInformation);
    }

    @GetMapping("/ticket/findTbTicketById")
    public Ticket findTbTicketById(Integer ticketId) {

        return ticketService.findTicketById(ticketId);
    }
}
